    <template>
    <div class="layout-route">
        <div class="card card-search">
            <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="100px">
                <el-form-item label="SPU" prop="spu">
                    <el-input v-model.trim="queryParams.spu" placeholder="请输入" clearable style="width: 240px" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="包裹号" prop="package_number">
                    <el-input v-model.trim="queryParams.package_number" placeholder="请输入" clearable style="width: 240px" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="物流单号" prop="track_number">
                    <el-input v-model.trim="queryParams.track_number" placeholder="请输入" clearable style="width: 240px" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="入库单号" prop="in_number">
                    <el-input v-model.trim="queryParams.in_number" placeholder="请输入" clearable style="width: 240px" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="创建人" prop="admin_id">
                <el-select v-model="queryParams.operate_id" placeholder="请选择" clearable filterable multiple>
                    <el-option v-for="(dict, index) in salesList" :key="index" :label="dict.admin_name" :value="dict.admin_id"></el-option>
                </el-select>
            </el-form-item>
                <el-form-item label="创建时间" prop="create_time">
                    <el-date-picker v-model="queryParams.create_time" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 240px">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label=" ">
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </div>

        <div class="card">
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" @click="showDetailDialog({}, 'add')">创建</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
            <el-tabs v-model="queryParams.in_stores_status" type="border-card" @tab-click="handleQuery">
                <el-tab-pane label="全部" :name="undefined"></el-tab-pane>
                <el-tab-pane v-for="item in tabList" :key="item.value" :label="item.label" :name="item.value.toString()"></el-tab-pane>
            </el-tabs>
            <div class="table-wrap">
                <el-table v-loading="loading" :data="tableData" border script>
                    <el-table-column label="入库单号" prop="in_number" min-width="120" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <el-button type="text" @click="showProductListDialog(scope.row)">{{scope.row.in_number}}</el-button>
                    </template>
                    </el-table-column>
                    <el-table-column label="图片" min-width="90">
                        <template slot-scope="scope">
                            <ImageUploadImg v-model="scope.row.image_url" :readOnly="true"></ImageUploadImg>
                        </template>
                    </el-table-column>
                    <el-table-column label="spu" prop="spu" min-width="90"></el-table-column>
                    <el-table-column label="商品种类" prop="sku_nums" min-width="90"></el-table-column>
                    <el-table-column label="包裹号 " prop="package_number" min-width="90"></el-table-column>
                    <el-table-column label="物流单号 " prop="track_number" min-width="90"></el-table-column>
                    <!-- <el-table-column label="入库类型" prop="in_stores_type" min-width="120">
                    <template slot-scope="scope">{{scope.row.in_stores_type == 1 ? '手动入库' : '退货入库'}}</template>
                    </el-table-column> -->
                    <el-table-column label="入库数量" prop="in_stores_quantity" min-width="120"></el-table-column>
                    <el-table-column label="备注" prop="remark" min-width="160" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <span :style="{color: scope.row.remark_color == 1 ? '#c03639' : '#30b08f'}">{{scope.row.remark}}</span>
                    </template>
                    </el-table-column>
                    <el-table-column label="创建人" prop="operater" min-width="160" show-overflow-tooltip></el-table-column>
                    <el-table-column label="创建时间" prop="create_time" min-width="160"></el-table-column>
                    <el-table-column label="操作" width="100" fixed="right">
                        <template slot-scope="scope">
                            <div><el-button v-if="queryParams.in_stores_status == 1" type="text" icon="el-icon-edit" @click="ConfirmReceipt(scope.row, 'edit')">确认入库</el-button></div>
                            <div><el-button type="text" icon="el-icon-document-add" @click="addRemark(scope.row)">备注</el-button></div>
                            <div><el-button v-if="queryParams.in_stores_status == 1" type="text" icon="el-icon-document-add" @click="showProductListDialog(scope.row)">编辑</el-button></div>
                            <div><el-button v-if="queryParams.in_stores_status == 1" type="text" icon="el-icon-document-add" @click="handleDelete(scope.row)">删除</el-button></div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList"></pagination>
        </div>

        <detail-dialog v-model="detailDialog.visible" v-if="detailDialog.visible" :params="detailDialog.data" :type="detailDialog.type" @success="handleQuery"></detail-dialog>
        <remark-dialog v-model="remarkDialog.visible" v-if="remarkDialog.visible" :params="remarkDialog.data" @success="handleQuery"></remark-dialog>
        <product-list-dialog v-model="productDialog.visible" v-if="productDialog.visible" :params="productDialog.data"></product-list-dialog>
    </div>
    </template>

    <script>

    import { getReStores,delReStores } from '@/api/warehouse'
    import { getOnSaleList } from '@/api/shop'
    import DetailDialog from './components/DetailDialog.vue'
    import RemarkDialog from './components/RemarkDialog.vue'
    import ProductListDialog from './components/ProductListDialog.vue'
    import { parseTime } from '@/utils/quickadmin'
    export default {
    name: 'InstoresList',
    components: { DetailDialog, RemarkDialog, ProductListDialog},
    data() {
        return {
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            tableData: [],
            salesList: [],
            tabList: [
                { label: '待入库', value: 1 },
                { label: '已入库', value: 2 }
            ],
            pageInfo: {
                page: 1,
                limit: 10,
            },
            // 查询参数
            queryParams: {
                spu: undefined,
                operate_id: undefined,
                in_number: undefined,
                remark: undefined,
                create_time: []
            },
            detailDialog: {
                visible: false,
                data: {},
            },
            remarkDialog: {
                visible: false,
                data: {},
            },
            productDialog: {
                visible: false,
                data: {},
            },
        }
    },
    async created() {
    this.loading = true
        try {
            const salesResult = await getOnSaleList()
            this.salesList = salesResult?.data ?? []
        } catch (error) {
            console.log(error)
        }
        this.loading = false
        this.getList()
    },
    methods: {
    ConfirmReceipt(row) {
        this.detailDialog.visible = true
            this.detailDialog.data = row
    },
        showDetailDialog(row) {
            this.detailDialog.visible = true
            this.detailDialog.data = row
        },
        showProductListDialog(row) {
            this.productDialog.visible = true
            this.productDialog.data = row
        },
        //列表
        getList() {
            this.loading = true
            const qyparams = {
                ...this.pageInfo,
                ...this.queryParams,
            }
            if (qyparams.create_time?.length == 2) {
                qyparams.create_time = [parseTime(qyparams.create_time[0], 'y-m-d'), parseTime(qyparams.create_time[1], 'y-m-d')]
            }
            getReStores(qyparams)
                .then(response => {
                    this.tableData = response.data.list
                    this.total = response.data.total
                })
                .finally(() => {
                    this.loading = false
                })
        },

        // 搜索按钮操作
        handleQuery() {
            this.pageInfo.page = 1
            this.getList()
        },

        // 重置按钮操作
        resetQuery() {
            this.resetForm('queryForm')

            this.handleQuery()
        },
        addRemark(row) {
            this.remarkDialog.visible = true
            this.remarkDialog.data = row
        },
        // 删除按钮操作
        handleDelete(row) {
            this.$confirm('是否确认删除?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(async () => {
                    // await delReStores({ id: row.id })
                    this.getList()
                    this.msgSuccess('删除成功')
                })
                .catch(() => {})
        },
    },
    }
    </script>
    <style scoped>
    ::v-deep .el-tabs .el-tabs__content {
    padding: 0;
    border-bottom: 0;
    }
    .el-tabs--border-card {
    box-shadow: none;
    border-bottom: 0;
    }

    ::v-deep .el-tabs .el-tabs__content {
    padding: 0;
    border-bottom: 0;
    }
    .table-wrap {
    padding: 15px;
    border-bottom: 1px solid #dfe4ed;
    border-left: 1px solid #dfe4ed;
    border-right: 1px solid #dfe4ed;
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
    }
    </style>
